package org.example.bio;

import java.io.*;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;

public class Server {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket();
        SocketAddress address = new InetSocketAddress("127.0.0.1",9000);
        serverSocket.bind(address);
        while(true){
            System.out.println("socket服务器开始启动...");
            System.out.println("bio同步阻塞");
            Socket socket = serverSocket.accept();
            InputStreamReader inputStreamReader = new InputStreamReader(socket.getInputStream());
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            System.out.println("接受输入流:"+bufferedReader.readLine());
            OutputStreamWriter out = new OutputStreamWriter(socket.getOutputStream());
            BufferedWriter bw = new BufferedWriter(out);
            bw.write("我已接受到你的需求");
            System.out.println("响应已回");
        }
    }
}
